﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta name="GENERATOR" content="Microsoft FrontPage 12.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>WebNoteEditor</title>
<link rel="STYLESHEET" type="text/css" id="SkinStyleSheet">
<style type="text/css">
#InputWidth,#InputHeight{
	width:30px;text-align:center;
}
</style>
<script language="javascript" type="text/javascript" src="../script/windialog.js"></script>
<script language="javascript">
var srcObject;
var DefaultWidth=280;
var DefaultVideoHeight=230;
var DefaultSoundHeight=45;
var DefaultFlashHeight=280;
var DefaultFLVPlayerWidth=280;
var DefaultFLVPlayerHeight=280;
var DefaultLoop=0;


var MediaPlayer_FileType_Sound=EditorWindow.MediaPlayer_FileType_Sound;
var QTimePlayer_FileType=EditorWindow.QTimePlayer_FileType;
var FlashPlayer_FileType=EditorWindow.FlashPlayer_FileType;
var MediaPlayer_FileType_Video=EditorWindow.MediaPlayer_FileType_Video;
var RealPlayer_FileType=EditorWindow.RealPlayer_FileType;
var FLVPlaver_FileType=EditorWindow.FLVPlaver_FileType;

var MediaPlayerString;
var AllowEx;

window.onload=function()
{
	EditorWindow.XEditor.focus();
	if (EditorWindow.XEditor.selection.type=="Control")
	{
		srcObject=EditorWindow.XEditor.objselected;
		
		document.getElementById("InputWidth").value=srcObject.clientWidth;
		document.getElementById("InputHeight").value=srcObject.clientHeight;
		if (srcObject.getAttribute("loop"))
			document.getElementById("InputLoop").value=srcObject.getAttribute("loop");
		if (srcObject.getAttribute("src"))
			document.getElementById("Movie").value=srcObject.getAttribute("src");
		if (srcObject.getAttribute("AUTOSTART")=="1")
			document.getElementById("CHK_AutoStart").checked=true;
			
		var extName=EditorWindow.getFileExt(document.getElementById("Movie").value);
		
		if (FlashPlayer_FileType.isInArray(extName))
		{
			var FlashVars=srcObject.getAttribute("FlashVars").toString();
			if (FlashVars.indexOf("."+FLVPlaver_FileType)>0 && document.getElementById("Movie").value.toString().indexOf("flvplayer.swf")>0)
			{
				//alert(FlashVars);
				document.getElementById("Movie").value=EditorWindow.getFLVFilePath(FlashVars);
				document.getElementsByName("CHK_FileType")[3].checked=true;
			}
			else
			{
				document.getElementsByName("CHK_FileType")[2].checked=true;
			}
		}	
		else if(MediaPlayer_FileType_Sound.isInArray(extName))
		{
			document.getElementsByName("CHK_FileType")[0].checked=true;
		}
		else
		{
			document.getElementsByName("CHK_FileType")[1].checked=true;
		}
	}
	else
	{
		document.getElementById("InputWidth").value=DefaultWidth
		//document.getElementById("InputHeight").value=DefaultVideoHeight;
		document.getElementById("InputLoop").value=DefaultLoop;
		MediaPlayerString="<EMBED style=\"height:$Height;width:$Width\" src=\"$FileName\" type=\"audio\/mpeg\" AUTOSTART=\"$AutoStart\" loop=\"$Loop\" FlashVars=\"$FlashVars\" allowFullScreen=\"True\">";
	}
	

	document.getElementById("sel_file").onchange=sel_file_onchange;

	AutoResizeDialogWindow();
	
}

function sel_file_onchange()
{
	var ExName;
	if (document.getElementById("sel_file").value!="")
	{
		AllowEx=MediaPlayer_FileType_Sound+","+MediaPlayer_FileType_Video+","+RealPlayer_FileType+","+FlashPlayer_FileType+","+QTimePlayer_FileType+","+FLVPlaver_FileType
		document.getElementById("Movie").value=getPath(document.getElementById("sel_file"));
		__autocheck();
	}
}

function __autocheck()
{
		ExName=EditorWindow.getFileExt(document.getElementById("Movie").value);
		if (MediaPlayer_FileType_Sound.isInArray(ExName))
		{
			document.getElementsByName("CHK_FileType")[0].checked=true;
			if(!document.getElementById("InputHeight").value)
				document.getElementById("InputHeight").value=DefaultSoundHeight;
			return;
		}
		
		if (MediaPlayer_FileType_Video.isInArray(ExName))
		{
			document.getElementsByName("CHK_FileType")[1].checked=true;
			if(!document.getElementById("InputHeight").value)
				document.getElementById("InputHeight").value=DefaultVideoHeight;
			return;
		}
		
		if (FlashPlayer_FileType.isInArray(ExName))
		{
			document.getElementsByName("CHK_FileType")[2].checked=true;
			if(!document.getElementById("InputHeight").value)
				document.getElementById("InputHeight").value=DefaultFlashHeight;
			return;
		}
		if (RealPlayer_FileType.isInArray(ExName))
		{
			document.getElementsByName("CHK_FileType")[1].checked=true;
			if(!document.getElementById("InputHeight").value)
				document.getElementById("InputHeight").value=DefaultVideoHeight;
			return;
		}
		
		if (FLVPlaver_FileType.isInArray(ExName))
		{
			document.getElementsByName("CHK_FileType")[3].checked=true;
			if(!document.getElementById("InputWidth").value)
				document.getElementById("InputWidth").value=DefaultFLVPlayerWidth;
			if(!document.getElementById("InputHeight").value)
				document.getElementById("InputHeight").value=DefaultFLVPlayerHeight;
			return;
		}
		//alert("error");
		document.getElementById("Movie").value="";
		alert(EditorWindow.tipsmsgReplace(EditorWindow.lang_tips_mediafileformaterror,"{0}|{1}",ExName+"|"+AllowEx));

}


function __btnOk_onclick()
{
	var returnHTML,FlashVars,FLVPlayerURL,FileName;
	if (document.getElementById("Movie").value=="")
	{
		alert(EditorWindow.lang_tips_selectmediafile)
		return;	
	}
	else
	{
		FileName=document.getElementById("Movie").value;
		__autocheck();
	}
	
	var Width,Height,AutoStart,LoopTime;
	Width=document.getElementById("InputWidth").value;
	Height=document.getElementById("InputHeight").value;
	LoopTime=document.getElementById("InputLoop").value;
		
	if (document.getElementById("CHK_AutoStart").checked)
		AutoStart=1;
	else
		AutoStart=0;

	if (srcObject)
	{
		srcObject.style.width=Width;
		srcObject.style.height=Height;
		srcObject.loop=LoopTime;
		
		if (document.getElementsByName("CHK_FileType")[3].checked)
		{
			FlashVars="vcastr_file=$vcastr_file&IsAutoPlay=0&LogoText=" + location.hostname;
			if (AutoStart==1)
			{
				FlashVars=FlashVars.replace("IsAutoPlay=0","IsAutoPlay=1");
			}
			else
			{
				FlashVars=FlashVars.replace("IsAutoPlay=1","IsAutoPlay=0");
			}
			FlashVars=FlashVars.replace("$vcastr_file",FileName);
			srcObject.setAttribute("FlashVars",FlashVars);
		}
		else
		{
			srcObject.src=FileName;
		}
		srcObject.autostart=AutoStart;
		
	}
	else
	{
		returnHTML=MediaPlayerString;
		
		returnHTML=returnHTML.replace("$Width",Width)
		returnHTML=returnHTML.replace("$Height",Height)
		returnHTML=returnHTML.replace("$AutoStart",AutoStart)
		returnHTML=returnHTML.replace("$Loop",LoopTime)
		
		if (document.getElementsByName("CHK_FileType")[3].checked)
		{
			FLVPlayerURL=("/"+location.pathname).toLowerCase();
			FLVPlayerURL=FLVPlayerURL.replace("dialogs/dialogplayer.htm",EditorWindow.DefaultFLVPlayerURL);
			returnHTML=returnHTML.replace("$FileName",FLVPlayerURL);
			FlashVars="vcastr_file=$vcastr_file&IsAutoPlay=0&LogoText=" + location.hostname;
			if (AutoStart==1)
			{
				FlashVars=FlashVars.replace("IsAutoPlay=0","IsAutoPlay=1");
			}
			else
			{
				FlashVars=FlashVars.replace("IsAutoPlay=1","IsAutoPlay=0");
			}
			
			FlashVars=FlashVars.replace("$vcastr_file",FileName);
			returnHTML=returnHTML.replace("$FlashVars",FlashVars);
		}
		else
		{
			returnHTML=returnHTML.replace("FlashVars=\"$FlashVars\"","");
			returnHTML=returnHTML.replace("$FileName",FileName);
		}
		EditorWindow.pasteHTML(returnHTML);
	
	}
	
	window.close();
}


function __btnCancel_onclick()
{
	window.close();
}

function getPath(obj)
{
	if(obj)
	{
		try
		{
			if (window.navigator.userAgent.indexOf("MSIE")>=1)
			{
				obj.select();
	
				return document.selection.createRange().text;
				
			}
			else if(window.navigator.userAgent.indexOf("Firefox")>=1)
			{
				if(obj.files)
				{
					return obj.files.item(0).getAsDataURL();
				}
				return obj.value;
			}
			return obj.value;
		}
		catch(e)
		{
			return obj.value;
		}
	}
}  

</script>
</head>

<body class="dialog">
<script language="javascript" type="text/javascript">dialogTitle("lang_insertmediafile")</script>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%">
    	<div style="position:relative;height:30px">
    		<input type="text" name="Movie" class="dialogInput" style="width:360px;height:20px;margin-bottom:-1px;z-index: 1;position: absolute">
    		<div style="z-index: 0;position:absolute;top:-3px;left:340px"><input id="sel_file" type="file" class="SysBTN5" size="0"></div>
    	</div>
    </td>
  </tr>
  <tr>
    <td width="100%">
        <input type="radio" value="sound" name="CHK_FileType"><script language="javascript" type="text/javascript">dialogPrintlang("lang_sound")</script>
        <input type="radio" value="movie" name="CHK_FileType"><script language="javascript" type="text/javascript">dialogPrintlang("lang_video")</script>
        <input type="radio" value="flash" name="CHK_FileType"><script language="javascript" type="text/javascript">dialogPrintlang("lang_flash")</script>
        <input type="radio" value="flv" name="CHK_FileType"><script language="javascript" type="text/javascript">dialogPrintlang("lang_flvvideo")</script>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <script language="javascript" type="text/javascript">dialogPrintlang("lang_mediaplayer")</script>
        :
        <script language="javascript" type="text/javascript">dialogPrintlang("lang_width")</script><input type="text" id="InputWidth" size="7" class="dialogInput" datatype="number">px
        <script language="javascript" type="text/javascript">dialogPrintlang("lang_height")</script><input type="text" id="InputHeight" size="7" class="dialogInput" datatype="number">px  
    </td> 
  </tr> 
  <tr> 
    <td width="100%"> 
        <input type="checkbox" name="CHK_AutoStart" value="ON" style="width: 20px"><script language="javascript" type="text/javascript">dialogPrintlang("lang_autoplay")</script>&nbsp;&nbsp;&nbsp; 
        <script language="javascript" type="text/javascript">dialogPrintlang("lang_loop")</script><input type="text" id="InputLoop" size="7" class="dialogInput" datatype="number"> 
    </td>
  </tr>

  <tr>
    <td width="100%">
    </td>
  </tr>
  <tr>
    <td width="100%" class="hr">
      <hr size="1" color="#B3AC9D">
    </td>
  </tr>
  <tr>
    <td width="100%" class="hr" align="right">
    	<script language="javascript" type="text/javascript">
    		PrintButtons2();
    	</script>
    </td>
  </tr>
</table>

</body>

</html>
